require('../../common/vendor.js');import pinyin from "@/util/jian_pinyin.js"
//  学号排序

export const studentCodeSort = (list, type) => {
    return list.sort((a, b) => {
        if (a[type].toLocaleUpperCase() > b[type].toLocaleUpperCase()) {
            return 1
        } else if (a[type].toLocaleUpperCase() < b[type].toLocaleUpperCase()) {
            return -1
        } else {
            return 0
        }
    })
}

//  座位号排序

export const studentSeatCodeSort = (list) => {
    return list.sort((a, b) => {
        if (a != "" && b != "") {
            if (isNaN(a * 1) && !isNaN(b * 1)) {
                return 1
            }
            if (!isNaN(a * 1) && isNaN(b * 1)) {
                return -1
            }

            if (!isNaN(a * 1) && !isNaN(b * 1)) {
                return a * 1 - b * 1
            }
        }

        if (a == "" && b != "") {
            return 1
        }
        if (a != "" && b == "") {
            return -1
        }
        return 0
    })
}

//  姓名排序

export const studentNameSort = (list, type) => {
    return list.sort((a, b) => {
        let a1 = pinyin
            .getSpell(a[type])
            .replace("[", "")
            .split("")
            .shift()
            .toLocaleUpperCase()
        let b1 = pinyin
            .getSpell(b[type])
            .replace("[", "")
            .split("")
            .shift()
            .toLocaleUpperCase()
        if (a1 < b1) {
            return -1
        } else if (a1 > b1) {
            return 1
        } else {
            return 0
        }
    })
}
